import React, { PureComponent } from 'react'
import Table from '../base/base-table'
import Input from 'antd/lib/input'
import Icon from 'antd/lib/icon'
import { getExceptionList } from '../../action/map.action'
import { connect } from 'react-redux'
import { millToString } from '../../util/util'

class ExceptionTable extends PureComponent {
    constructor () {
        super()
    }

    shouldComponentUpdate (nextProps) {
        return nextProps.exceptionList !== this.props.exceptionList
    }

    componentDidMount () {
        const {dispatch} = this.props
        dispatch(getExceptionList())
    }

    render () {

        const {onClick, exceptionList} = this.props
        const columns = [
            {
                title: '序列号',
                dataIndex: 'sendNumber',
                key: 'sendNumber',
                className: 'go-down',
                width: '10%',
                onCellClick: onClick
            }, {
                title: '问题描述',
                dataIndex: 'problemDesc',
                key: 'problemDesc',
                width: '30%',
            }, {
                title: '处理人',
                dataIndex: 'userEmail',
                key: 'userEmail',
                width: '8%',
                render(value = ''){
                    return value.split('@')[0]
                }
            },
            {
                title: '责任部门',
                dataIndex: 'departments',
                key: 'departments',
                width: '10%',
            },
            {
                title: '状态',
                dataIndex: 'status',
                key: 'status',
                width: '8%',
                render(value){
                    switch (+value) {
                        case 0:
                            return '未处理'
                        case 1:
                            return '已处理'
                    }
                }
            }
        ]

        const data = exceptionList.toJS().sort((a, b) => (a.status - b.status))
        return (
            <div style={{height: '100%', margin: '1rem'}} className="scheduling-table-container">
                <Table columns={columns} dataSource={data} pagination={{pageSize: 15}} border={true}/>
            </div>
        )
    }

}

function mapStateToProps ({exceptionList}) {
    return {exceptionList}
}

export default connect(mapStateToProps)(ExceptionTable)
